#include<cstdio>//uncle-lu
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int n;
int l[40001], r[40001];
long long int F[40001][40][40];
long long int a[40001], b[40001], c[40001];
int cnt_1[40001], cnt_2[40001];

void init(int x)
{
	if(x >= n)return;//叶子节点 -- 乡村节点.
	cnt_1[l[x]] = cnt_1[x] + 1;
	cnt_1[r[x]] = cnt_1[x];
	cnt_2[r[x]] = cnt_2[x] + 1;
	cnt_2[l[x]] = cnt_2[x];
	init(l[x]);
	init(r[x]);
	return ;
}

void DFS(int x)
{
	if(x >= n)
	{
		for (int i = 0; i <= cnt_1[x]; i++) 
			for (int j = 0; j <= cnt_2[x]; j++) 
				F[x][i][j] = c[x] * (a[x] + i) * (b[x] + j);
	}
	else
	{
		DFS(l[x]);
		DFS(r[x]);
		for (int i =  0; i <= cnt_1[x]; i++) 
			for (int j =  0; j <= cnt_2[x]; j++) 
				F[x][i][j] = std::min(F[l[x]][i+1][j] + F[r[x]][i][j], F[l[x]][i][j] + F[r[x]][i][j+1]);
	}
	return ;
}

int main()
{
	read(n);
	for (int i = 1; i < n; i++) 
	{
		read(l[i]);read(r[i]);
		if(l[i] < 0) l[i] = n - l[i] - 1;
		if(r[i] < 0) r[i] = n - r[i] - 1;
	}
	for (int i = 1; i <= n; i++) 
	{
		int x = n + i - 1;
		read(a[x]);read(b[x]);read(c[x]);
	}

	init(1);

	DFS(1);

	printf("%lld", F[1][0][0]);
	return 0;
}
